﻿using Microsoft.Extensions.Caching.Memory;
using OA.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OA.BLL
{
    public class CCountersignEmployee
    {
        public void Map(List<CountersignEmployee> list, IMemoryCache _cache)
        {
            if (list == null) return; 
            CacheHelper cacheHelper = new CacheHelper(_cache);
            List<Department> listDepartment = cacheHelper.GetDepartments();
            List<Position> listPosition = cacheHelper.GetPositions();
            List<Employee> listEmployee = cacheHelper.GetEmployees();

            foreach (CountersignEmployee item in list)
            {
                Position itemPosition = listPosition.Where(m => m.ID == item.PositionID).FirstOrDefault();
                if (itemPosition != null)
                {
                    item.PositionName = itemPosition.Name;
                    Department infoDepartment = listDepartment.Where(m => m.ID == itemPosition.DepartmentID).FirstOrDefault();
                    if (infoDepartment != null)
                    {
                        item.DepatrmentName = infoDepartment.Name;
                    }

                }
                Employee itemEmployee = listEmployee.Where(m => m.EmpID == item.EmpID).FirstOrDefault();
                if (itemEmployee != null)
                {
                    item.EmpName = itemEmployee.EmpName;
                }
            }
        }
    }
}
